/*
 * Copyright 2006 Polar Rose <http://www.polarrose.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.polarrose.amazon.sqs;

import java.io.Serializable;

/**
 * @author Stefan Arentz <stefan@polarrose.com>
 */

public class SqsMessage implements Serializable {

	private static final long serialVersionUID = 4707000238543950504L;

	private String id;
	private String body;
	private String messageMd5;
	private String receiptHandle;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public SqsMessage() {
	}

	public String getMessageMd5() {
		return messageMd5;
	}

	public void setMessageMd5(String messageMd5) {
		this.messageMd5 = messageMd5;
	}

	public String getReceiptHandle() {
		return receiptHandle;
	}

	public void setReceiptHandle(String receiptHandle) {
		this.receiptHandle = receiptHandle;
	}

	public SqsMessage(String id, String body, String messageMd5) {
		setId(id);
		setBody(body);
		setMessageMd5(messageMd5);
	}

	public SqsMessage(String id, String body) {
		setId(id);
		setBody(body);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((body == null) ? 0 : body.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((messageMd5 == null) ? 0 : messageMd5.hashCode());
		result = prime * result + ((receiptHandle == null) ? 0 : receiptHandle.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SqsMessage other = (SqsMessage) obj;
		if (body == null) {
			if (other.body != null)
				return false;
		} else if (!body.equals(other.body))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (messageMd5 == null) {
			if (other.messageMd5 != null)
				return false;
		} else if (!messageMd5.equals(other.messageMd5))
			return false;
		if (receiptHandle == null) {
			if (other.receiptHandle != null)
				return false;
		} else if (!receiptHandle.equals(other.receiptHandle))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "SqsMessage[messageId = " + id + ", messageMd5 = " + messageMd5 + ", receiptHandle = " + receiptHandle + ", body = " + body + "]";
	}
}
